import java.util.Scanner;

public class BinaryOrdering {
    //二分排序法
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);
        int[] numList = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        int left = 0, right = numList.length - 1, flag = 0;
        int mid = 0, target;
        for (int j : numList) System.out.printf("%d ", j);

        System.out.println("\n请输入要查找的整数，按回车结束");
        target = read.nextInt();
        while (left <= right) {
            mid = (left + right) / 2;
            if (target==numList[mid]) {
                flag=1;
                break;
            }
            else if(target<numList[mid])
                right=mid-1;
            else
                left=mid+1;
        }
        if(flag==1)
            System.out.println("输入数字"+target+"在数组中的下标是"+mid);
        else
            System.out.println("输入数字"+target+"在数组中未查找到");

    }
}
